home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / C2SND201.ZIP / SND2WAV.DOC < prev    next >
Text File  |  1994-09-11  |  21KB  |  493 lines

  1.  
  2.  
  3.  
  4.              Snd2wav:  Converter for Tandy DeskMate .snd Files
  5.              -------------------------------------------------
  6.  
  7. Version 1.1
  8.  
  9. Written by:
  10.   Jeffrey L. Hayes
  11.   130 Forest Ave., Lot 1
  12.   Orono, Me. 04473
  13.   (207) 866-7903
  14.   Internet:  tvdog@delphi.com
  15.  
  16. This program is in the public domain.
  17.  
  18.  
  19. Contents:
  20.  
  21.     1. Purpose
  22.     2. How to Use Snd2wav
  23.     3. Possible Problems
  24.     4. About .snd Files
  25.     5. Other Programs for the Tandy Sound Chip
  26.  
  27.  
  28. 1. Purpose
  29.  
  30.    This is a companion program to Kenneth Udut's Conv2snd program for 
  31.    converting .wav and other formats to .snd.  I did the revisions for 
  32.    version 2.00 of that program.
  33.  
  34.    This program converts DeskMate .snd files to RIFF WAVE format, allowing 
  35.    them to be played without the DeskMate Sound.pdm program.  This allows 
  36.    sounds edited with Sound.pdm to be shared with users on non-Tandy 
  37.    machines.
  38.  
  39.    Version 1.1 now supports the new-format .snd files used on the 2500- 
  40.    series.
  41.  
  42.  
  43. 2. How to Use Snd2wav
  44.  
  45.    The simplest way to use Snd2wav is just to type its name:
  46.  
  47.      snd2wav
  48.  
  49.    The program will prompt you for the input filename (i.e., the .snd 
  50.    file).  The filename may include drive and/or path.  If you do not 
  51.    specify an extension, it defaults to ".snd".  You may specify a file 
  52.    without an extension by ending the filename with a period.  The output 
  53.    filename will be the same as the input filename you specify, including 
  54.    drive and/or path, but with a ".wav" extension.
  55.  
  56.    You can also specify the input file on the command line:
  57.  
  58.      snd2wav a:\sounds\scream
  59.  
  60.    The above will convert a:\sounds\scream.snd to a:\sounds\scream.wav (and 
  61.    possibly more - see below).  Or you can specify both the input and 
  62.    output filenames:
  63.  
  64.      snd2wav c:oldsnd.snd \newsnd.
  65.  
  66.    The above will convert file "oldsnd.snd" in the current directory of 
  67.    drive C: and place the result in the root directory of the current drive 
  68.    as "newsnd" (without an extension).
  69.  
  70.    If all goes well, you will see something like the following:
  71.  
  72.      C:>snd2wav spockd
  73.  
  74.      Snd2wav, v. 1.1:  DeskMate .snd to RIFF WAVE conversion program.
  75.  
  76.      Converting:  spockd.snd
  77.        Creating:  spockd.wav
  78.  
  79.      Conversion complete.  Thank you for using Snd2wav.
  80.  
  81.    You may also see this if you convert an instrument file with more than 
  82.    one note defined:
  83.  
  84.      I:\CONV2SND>snd2wav piano new
  85.  
  86.      Snd2wav, v. 1.1:  DeskMate .snd to RIFF WAVE conversion program.
  87.  
  88.      Converting:  piano.snd
  89.        Creating:  new.wav
  90.        Creating:  new2.wav
  91.        Creating:  new3.wav
  92.  
  93.      Conversion complete.  Thank you for using Snd2wav.
  94.  
  95.    If the .snd is an instrument file with more than one note defined, 
  96.    Snd2wav converts each note to a separate .wav file, as above.  There can 
  97.    be up to 16 notes in an .snd file.  Snd2wav will generate new names from 
  98.    the original output filename as necessary by appending a digit, as 
  99.    above.  The "digits" for the 10th through the 16th notes are letters "A" 
  100.    through "G".  If the output filename is already 8 characters long, the 
  101.    last character will be overwritten by the digit:
  102.  
  103.      I:\CONV2SND>snd2wav cello longname.
  104.  
  105.      Snd2wav, v. 1.1:  DeskMate .snd to RIFF WAVE conversion program.
  106.  
  107.      Converting:  cello.snd
  108.        Creating:  longname.
  109.        Creating:  longnam2.
  110.        Creating:  longnam3.
  111.  
  112.      Conversion complete.  Thank you for using Snd2wav.
  113.  
  114.    That's it.  The output file is a valid .wav file playable on any machine 
  115.    with a .wav player.
  116.  
  117.  
  118. 3. Possible Problems
  119.  
  120.    If something goes wrong during the conversion, Snd2wav will do its best 
  121.    to tell you what it thinks the problem was, and what you should do about 
  122.    it.  Its word should not be taken as gospel, however; it's just making 
  123.    its best guess about the probable cause of something that may have many 
  124.    possible causes.
  125.  
  126.    One error message that you are certain to see if you run out and try to 
  127.    convert the .snd files that came with DeskMate is the following:
  128.  
  129.  I:\CONV2SND>snd2wav h:piano.snd i:piano
  130.  
  131.  Snd2wav, v. 1.1:  DeskMate .snd to RIFF WAVE conversion program.
  132.  
  133.  The input file you specified:  h:piano.snd
  134.  ... is compressed.  Snd2wav can't convert compressed .snd's.  Load the file
  135.  into Sound.pdm, turn compression off, and resave the file.  Then try again.
  136.  
  137.    You can convert piano.snd if you follow those directions.  Compressed 
  138.    .snd's, as the message says, can't be converted.  I don't know the 
  139.    compression algorithms used by Tandy, so this program can't interpret 
  140.    compressed sound data.
  141.  
  142.    Here is something else you might see:
  143.  
  144.  I:\CONV2SND>snd2wav piano b:piano
  145.  
  146.  Snd2wav, v. 1.1:  DeskMate .snd to RIFF WAVE conversion program.
  147.  
  148.  Converting:  piano.snd
  149.  
  150.  Unable to create file b:piano.wav.
  151.  Either the name is not a valid filename, or the disk is write-protected, or
  152.  there is already a read-only file with that name.  Check the filename and
  153.  unprotect the disk, then try again.
  154.  
  155.    In this case, I have a write-protected disk in drive B:.  I have to 
  156.    remove the write-protection before I can write files on B:.
  157.  
  158.    Here is another that might be pretty common:
  159.  
  160.  I:\CONV2SND>snd2wav nosound
  161.  
  162.  Snd2wav, v. 1.1:  DeskMate .snd to RIFF WAVE conversion program.
  163.  
  164.  Converting:  nosound.snd
  165.  
  166.  Note number 1 of the input .snd file contains no samples.  The .snd file was
  167.  saved after a note was created but before sound was recorded for the note, or
  168.  the .snd file is a new sound file with no data recorded into it.  This note is
  169.  being skipped.
  170.  
  171.  Conversion complete.  Thank you for using Snd2wav.
  172.  
  173.    I'm trying to convert a file with no sound in it.  What I did was start 
  174.    Sound.pdm without loading a data file, then "Save as ...".  Note the 
  175.    "Conversion complete" message: Snd2wav does not consider this an error.  
  176.    There just isn't any sound to convert, so there isn't any output .wav 
  177.    created.  The "Note number 1" might throw you if you haven't dealt with 
  178.    instrument files.  Instrument files can contain several different sound 
  179.    samples for different musical notes.  When it's converting an instrument 
  180.    file, Snd2wav makes a different .wav file for each note.  The easiest 
  181.    way for me to do that sort of thing was to treat sound files as if they 
  182.    were instrument files with one note.  In the above example, nosound.snd 
  183.    is a sound file that has nothing recorded into it.  If I had an 
  184.    instrument file with something recorded into some notes but not others, 
  185.    I would have seen the message above for the unrecorded notes, but the 
  186.    recorded notes would have been converted correctly:
  187.  
  188.  I:\CONV2SND>snd2wav cello
  189.  
  190.  Snd2wav, v. 1.1:  DeskMate .snd to RIFF WAVE conversion program.
  191.  
  192.  Converting:  cello.snd
  193.    Creating:  cello.wav
  194.    Creating:  cello2.wav
  195.  
  196.  Note number 3 of the input .snd file contains no samples.  The .snd file was
  197.  saved after a note was created but before sound was recorded for the note, or
  198.  the .snd file is a new sound file with no data recorded into it.  This note is
  199.  being skipped.
  200.  
  201.  Conversion complete.  Thank you for using Snd2wav.
  202.  
  203.    Finally, here is an error you are likely to see if you make misteaks 
  204.    when you type, like I do:
  205.  
  206.  I:\CONV2SND>snd2wav celo
  207.  
  208.  Snd2wav, v. 1.1:  DeskMate .snd to RIFF WAVE conversion program.
  209.  
  210.  File celo.snd does not exist.
  211.  Check the filename and try again.
  212.  
  213.    One known *BUG* in this program is that it won't convert read-only .snd 
  214.    files, insisting that they "do not exist."  This is a bug in the Turbo 
  215.    Pascal runtime library, and I don't have any immediate plans to fix it.  
  216.    The bug applies only to files made read-only with the Attrib +r command, 
  217.    not to files on a write-protected floppy disk.  Use Attrib -r to 
  218.    unprotect your .snd file before you convert it (Snd2wav does not modify 
  219.    the .snd file).
  220.  
  221.    There are several other, less common, error messages you can get.  What 
  222.    you should never see is a message like this:
  223.  
  224.  Runtime error 200 at 0000:1A3E.
  225.  
  226.    This type of error message indicates that I made a mistake in writing 
  227.    the program.  If you get a message like this, I need to know about it so 
  228.    I can fix the problem in the next version of Snd2wav.  You can reach me 
  229.    by phone, by U.S. mail, or by email, whatever is convenient.  Be sure to 
  230.    write down the message so you can tell me what it says.  See the top of 
  231.    this file to find out how to reach me.
  232.  
  233.    If you get any kind of error message you don't understand, call or write 
  234.    me and we will try to figure it out.
  235.  
  236.    For use in batch files, Snd2wav will return errorlevel 1 if anything 
  237.    goes wrong during the conversion, or errorlevel 0 if all is OK.
  238.  
  239.  
  240. 4. About .snd Files
  241.  
  242.    The following is provided for the benefit of those who may wish to 
  243.    create other programs using the Tandy DeskMate .snd format.  You do not 
  244.    need to know anything in this section to use this program.
  245.  
  246.    There are two types of DeskMate .snd files, sound files and instrument 
  247.    files.  Both contain 8-bit unsigned PCM samples.  "PCM" stands for 
  248.    "pulse code modulation" and just means that the sound wave is sampled at 
  249.    fixed intervals and its level recorded.  It's just like you used to do 
  250.    in high school algebra when you were asked to graph a function by 
  251.    evaluating it at various points.  With Tandy PCM, the samples are 
  252.    integers in the range 0-255.
  253.  
  254.    Sound files are the simpler of the two types of .snd files.  These are 
  255.    garden-variety sample files with a fixed-length header giving the name 
  256.    of the sound, the recording frequency, and the length of the sound.  
  257.    Sound files may be recorded at 5500Hz, 11kHz or 22kHz.
  258.  
  259.    Instrument files contain samples as well as frequency and looping 
  260.    information used by Music.pdm to represent an instrument.  Instrument 
  261.    files provide for attack, sustain, and decay with several samples having 
  262.    different implied frequencies and being used by Music.pdm to represent 
  263.    the instrument in different pitch ranges.  Up to 16 different notes 
  264.    (with 16 different samples) can be contained in one instrument file.  
  265.    Instrument files are always recorded at 11kHz.  Snd2wav discards the 
  266.    extra information when converting instrument files, only extracting the 
  267.    note samples themselves.  There is no standard place in the .wav format 
  268.    to put the extra information (it could conceivably go in an INFO chunk, 
  269.    but Snd2wav doesn't do that).
  270.  
  271.    Both sound files and instrument files may be compressed in one of two 
  272.    ways, "music" compression or "speech" compression, or they may be 
  273.    uncompressed.  I don't know the compression algorithms, but simple file 
  274.    comparison reveals that "music" and "speech" compression are almost 
  275.    identical.
  276.  
  277.    The old-format DeskMate .snd file header consists of 16 bytes of fixed 
  278.    header information followed by one or more 28-byte note records.  The 
  279.    sample information, which may be compressed, follows the header.  The 
  280.    new-format .snd file header, used on the 2500-series, consists of 114 
  281.    bytes of fixed header followed by one or more 46-byte note records; it 
  282.    contains essentially the same information as the old header.  Conv2snd 
  283.    creates old-format .snd files; the 2500's can read the old format.
  284.  
  285.    Many of the numbers below are given in hexadecimal, or base-16 notation.  
  286.    Hexadecimal is a common way to express numbers when programming at the 
  287.    machine level.  In base-16, letters A through F are used to represent 
  288.    "digits" 10 through 15.  Also: "word" is a 16-bit unsigned integer, and 
  289.    "dword" is a 32-bit unsigned integer.
  290.  
  291.    "American Standard Pitch" refers to the sound frequencies assigned to 
  292.    the various musical notes by the American Standards Association.  Sound 
  293.    frequencies are based on A above middle C being 440 cycles per second.  
  294.    This A is called A4.  An octave below that is A3, an octave above, A5.  
  295.    The frequency doubles with each octave increase in pitch.  Sound.pdm 
  296.    does not display standard notes to you, though.  Standard octaves begin 
  297.    at C, so you would have A#2, B2, C3.  Sound.pdm starts its octaves at A.
  298.  
  299.    The sampling rate has nothing to do with the pitch frequency, except 
  300.    that the rate must be at least twice as high as the highest frequency 
  301.    you want to record.
  302.  
  303.    DeskMate .snd File Format - Fixed Header
  304.    ----------------------------------------
  305.  
  306.    offset    size      what
  307.    ------    ----      ----
  308.  
  309.    0         byte      1Ah (.snd ID byte).  Note that 1Ah = <cntrl>-Z, so
  310.                        if a user attempts to type the .snd file to the screen,
  311.                        nothing will be displayed.
  312.  
  313.    1         byte      Compression code:  0 = no compression; 1 = music
  314.                        compression; 2 = speech compression.
  315.  
  316.    2         byte      Number of notes in the instrument file.  1 if sound
  317.                        file.  There can be up to 16 notes in an instrument
  318.                        file.  Note:  when an instrument file is created, it
  319.                        automatically has one unset note placed in it.
  320.  
  321.    3         byte      Instrument number.  0 if sound file; 0FFh if instrument
  322.                        file with no number set.  Valid instrument numbers in
  323.                        an instrument file are 1 to 32.  Use this field to
  324.                        distinguish a sound file from an instrument file.
  325.  
  326.    4         10 bytes  Sound or instrument name.  Name is a null-terminated
  327.                        string, so there are up to 9 characters of the name,
  328.                        plus the null byte.
  329.  
  330.    0Eh       word      Sampling rate in samples per second.  Note that
  331.                        although a sampling rate other than 5500, 11000 and
  332.                        22000 can be entered here, Sound.pdm will not actually
  333.                        play at other rates.
  334.  
  335.    10h       variable  Note records begin, 28 bytes each.  Number of records
  336.                        given in byte 2 above.
  337.  
  338.  
  339.    DeskMate .snd File Format - Note Record
  340.    ---------------------------------------
  341.  
  342.    0         byte      Pitch of the note:  1 = A1 in American Standard Pitch;
  343.                        2 = A#1; etc.  A1 is lowest note allowed; highest note
  344.                        allowed is B6 (3Fh).  Sound files have 0FFh here; so do
  345.                        instrument files with no note set.
  346.                            Note that Sound.pdm does not designate notes in the
  347.                        standard manner to the user.  Although A1 and B6 in
  348.                        Sound.pdm are the same as A1 and B6 in standard pitch,
  349.                        Sound.pdm starts octaves at A rather than at C (as is
  350.                        standard).  Thus, middle C, C4 in standard pitch, is C3
  351.                        in Sound.pdm.
  352.  
  353.    1         byte      Sound files, and instrument files with no pitch set,
  354.                        have 0 here.  If the pitch is set, this byte is 0FFh.
  355.  
  356.    2         2 bytes   Range of the note, first byte is lower limit, second
  357.                        is higher limit.  Byte encoding as for offset 0 (i.e.,
  358.                        01h to 3Fh).  Sound files have FF FF here; so do
  359.                        instrument files with no range set.
  360.  
  361.    4         dword     Offset in the file where samples for this note begin
  362.                        (zero-relative), after compression if that was done.
  363.  
  364.    8         dword     If compressed, the length of the compressed data in the
  365.                        file for this note.  Uncompressed files have 0 here.
  366.  
  367.    0Ch       4 bytes   Unknown.  Set to zero.
  368.  
  369.    10h       dword     Number of samples in the note, after decompression if
  370.                        necessary.  0 can appear here.
  371.  
  372.    14h       dword     Number of sample at start of sustain region for the
  373.                        note, relative to the first (zeroth) sample of the note.
  374.                        For sound files, or if sustain is not set, this field is
  375.                        0.
  376.  
  377.    18h       dword     Number of sample at end of sustain region for the note,
  378.                        relative to the first (zeroth) sample of the note.  For
  379.                        sound files, or if sustain is not set, this field is 0.
  380.  
  381.  
  382.    For new-format files, the header looks like this:
  383.  
  384.    New Tandy .snd File Format - Fixed Header
  385.    -----------------------------------------
  386.  
  387.    offset    size      what
  388.    ------    ----      ----
  389.    
  390.    0         10 bytes  Null-terminated sound name.
  391.  
  392.    0Ah       34 bytes  Unknown.
  393.  
  394.    2Ch       2 bytes   New .snd ID:  1Ah 80h.
  395.  
  396.    2Eh       word      Number of notes in the file.
  397.  
  398.    30h       word      Sound (instrument) number.
  399.  
  400.    32h       16 bytes  Unknown.
  401.  
  402.    42h       word      Compression code (0 = no compression, 1 = music
  403.                        compression, 2 = speech compression).
  404.  
  405.    44h       20 bytes  Unknown.
  406.  
  407.    58h       word      Sampling rate in samples per second.
  408.  
  409.    5Ah       24 bytes  Unknown.
  410.  
  411.    72h       variable  Note records begin.  Number given by word at 2Eh above.
  412.  
  413.  
  414.    New Tandy .snd File Format - Note Record
  415.    ----------------------------------------
  416.    
  417.    0         dword     Link to next note record (offset in file of next note
  418.                        record).  0 if last.
  419.  
  420.    4         2 bytes   Unknown.
  421.  
  422.    6         byte      Pitch of note (01h-3Fh), 01 = A1 in American Standard
  423.                        Pitch; 0FFh if not set.
  424.  
  425.    7         byte      Unknown (compare old .snd format; value is 00h or 0FFh,
  426.                        but seemingly unrelated to the pitch setting).
  427.  
  428.    8         2 bytes   Range of note.  First byte is lower limit, second is
  429.                        higher limit.  Values as for byte at offset 6 above;
  430.                        0FFh 0FFh if not set.
  431.  
  432.    0Ah       dword     Offset in file of start of sound data for this sample.
  433.  
  434.    0Eh       dword     Length of sample sound data in bytes.
  435.  
  436.    12h       dword     Uncompressed length of sound data (number of samples).
  437.  
  438.    16h       24 bytes  Unknown.
  439.  
  440.  
  441. 5. Other Programs for the Tandy Sound Chip
  442.  
  443.    There are programs other than Sound.pdm that can record sounds on a 
  444.    Tandy with the proprietary sound.  Here are a few of them.  All can 
  445.    record and play back sounds of arbitrary length, unlike Sound.pdm.  None 
  446.    allows you to edit sounds as Sound.pdm does.  The first two are share- 
  447.    ware; the last is free.
  448.  
  449.    David Stewart's Sampler package records and plays raw headerless samples 
  450.    at near 11kHz and features voice activation.  The registered version 
  451.    purportedly provides keyboard activation (nice because the voice 
  452.    activation seems to have a will of its own) and allows the sampling rate 
  453.    to be varied.
  454.  
  455.    Sean Haynes' Tndsound program records and plays sound files in its own 
  456.    proprietary format.  The unregistered version of this package does not 
  457.    appear to be crippled.  There is a menu-driven interface.  This program 
  458.    offers sound filtering and control over the playback volume.  Overall, I 
  459.    would say that Tndsound is better than Sampler.  One drawback to this 
  460.    program is that it doesn't know how to compute the sampling rate in Hz 
  461.    from the DAC divider value, so it's hard to select a standard sampling 
  462.    rate (you have to specify the rate as a meaningless number).  The 
  463.    default rate is around 9kHz.
  464.  
  465.    My Tspak package contains a program, Recwav, to record RIFF WAVE files 
  466.    at an arbitrary sampling rate (the default is 11kHz).  It runs from the 
  467.    DOS command line.  The rate is set in Hz.  There is also a program, 
  468.    Playwav, that can play 8- or 16-bit mono or stereo .wav's at up to 65535 
  469.    Hz.  Tspak contains other programs useful to Tandy owners, including one 
  470.    to convert .snd files to Amiga .mod samples for use in a .mod editor, 
  471.    and another to enable the Tandy DAC to be used with some programs that 
  472.    otherwise would not support it.  Tspak also comes with source code and 
  473.    programming information if you want to write your own programs for the 
  474.    Tandy sound chip.
  475.  
  476.    Sampler and Tndsound are on Delphi in the PC-Compatibles .sig, Crossfire 
  477.    Database.  If you are not on Delphi, write me and I'll mail you a copy.  
  478.    Tspak is on Simtel.  ftp to:
  479.  
  480.      oak.oakland.edu
  481.  
  482.    and get file:
  483.  
  484.      /pub/msdos/sound/tspak.zip
  485.  
  486.    It is also worth noting that there is a Windows 3.1 sound driver for the 
  487.    Tandy DAC, available on some BBS's and from Radio Shack.  It will work 
  488.    on the 1000RSX and the 2500-series.
  489.  
  490. Happy listening!
  491.  
  492. Jeff (tvdog@delphi.com)
  493.